package com.osdp.uc.feign;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.osdp.common.constant.CommonConstant;
import com.osdp.sc.dto.PermissionDTO;
import com.osdp.sc.dto.RoleDTO;
import com.osdp.sc.dto.TenantUserDTO;
import com.osdp.uc.dto.OrganizationDTO;
import com.osdp.uc.dto.PositionDTO;
import com.osdp.uc.dto.UserDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Optional;
import java.util.Set;

@FeignClient(value = CommonConstant.UC_APP_NAME, path = CommonConstant.UC_APP_PATH, fallbackFactory = UcFeignServiceFallbackFactory.class)
public interface UcFeignService {

    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @GetMapping("/v1/rest/user/byUsername")
    UserDTO queryUserByUserName(@RequestParam(value = "userName") String userName);

    /**
     * 用于用户登录，登录后放入缓存的登录用户信息
     * @param userId String
     * @return  Result<UserDTO>
     */
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @GetMapping("/v1/rest/user/byId")
    UserDTO queryUserById(@RequestParam(value = "userId") String userId);

    @ApiOperation(value = "查询所有用户列表（分页）", notes = "查询所有用户列表（分页）")
    @PostMapping("/v1/rest/user/pageList")
    IPage<UserDTO> userPageList(@RequestBody UserDTO userDTO,
                                        @RequestParam(name = "pageNo", defaultValue = "1") int pageNo,
                                        @RequestParam(name = "pageSize", defaultValue = "10") int pageSize);


    @GetMapping("/v1/rest/user/updatePassWord")
    Boolean updatePassWord(@RequestParam(value = "id")  String id,
                                          @RequestParam(value = "passWord") String passWord);

    /**
     * 根据用户ID对应的岗位信息
     * @param userId
     * @return List<PositionVo>
     */
    @ApiOperation(value = "根据用户ID获取岗位信息", notes = "获取岗位信息")
    @GetMapping("/v1/rest/position/positionByUserId")
    List<PositionDTO> queryPositionByUserId(@RequestParam(value = "userId") String userId);

    /**
     * 根据用户ID得到相应的组织机构
     * @param userId
     * @return List<OrganizationVo>
     */
    @ApiOperation(value = "根据用户ID获取部门信息", notes = "获取部门信息")
    @GetMapping("/v1/rest/org/orgByUserId")
    List<OrganizationDTO> queryOrganizationByUserId(@RequestParam(value = "userId") String userId);

    //------------------------------------------------------------//
    /**
     * 根据用户Id得到所有角色，用于登录
     * @param userId String
     * @return List<RoleVo>
     */
    @ApiOperation(value = "根据用户ID获取角色信息", notes = "获取角色信息")
    @GetMapping("/v1/rest/role/roleIdsByUserId")
    List<RoleDTO> getRolesByUserId(@RequestParam(value = "userId") String userId);

    /**
     * 根据用户ID查询角色编码
     * @param userId
     * @return
     */
    @GetMapping("/v1/rest/role/roleCodes")
    List<String> getRoleCodeByUserId(@RequestParam(value = "userId")String userId);

    /**
     * 根据用户ID 查询权限
     * @param userId String
     * @return List<ScPermission>
     */
    @GetMapping("/v1/rest/perms/permsByUserId")
    List<PermissionDTO> queryPermissionsByUserId(@RequestParam(value = "userId")String userId);

    /**
     * 查询所有按钮资源
     * @return List<PermissionVo>
     */
    @GetMapping("/v1/rest/perms/permsButByUserId")
    List<PermissionDTO> queryPermissionButtonByUserId(@RequestParam(value = "userId")String userId);

    /**
     * 查询API权限集合
     * @param userId String 用户ID
     * @return List<PermissionVo>
     */
    @GetMapping("/v1/rest/perms/permsApiByUserId")
    List<PermissionDTO> queryPermissionAPIByUserId(@RequestParam(value = "userId")String userId);

    /**
     * 根据用户ID查询资源权限 code
     * @param userId String
     * @return
     */
    @GetMapping("/v1/rest/perms/permsCodeByUserId")
    List<String> queryPermsCodeByUserId(@RequestParam(value = "userId")String userId);

    /**
     * 根据角色编码查询所有按钮与API资源
     * @param roleCodes Set<String>
     * @param tenantId String
     * @return Optional<List<PermissionDTO>>
     */
    @PostMapping("/v1/rest/perms/permsButAndApis")
    Optional<List<PermissionDTO>> queryPermsButtonAndAPIByRoleCode(@RequestBody Set<String> roleCodes,
                                                                   @RequestParam(value = "tenantId") String tenantId);

    /**
     * 根据用户ID查询对应的角色id
     * @param userId
     * @return
     */
    @ApiOperation(value = "根据用户ID获取角色信息", notes = "获取角色信息")
    @GetMapping("/v1/rest/role/roleIdsByUserId")
    List<String> queryRoleIdByUserId(@RequestParam(value = "userId") String userId);

    /**
     * 根据用户ID得到租户ID
     * @param userId
     * @return
     */
    @GetMapping("/v1/rest/tenant/tenantsByUserId")
    List<TenantUserDTO> queryTenantByUserId(@RequestParam(value = "userId") String userId);

    /**
     * 获取与与租户编码一致的租户id
     *
     * @param tenants
     * @param tenantCode
     * @return
     */
    @PostMapping("/v1/rest/tenant/currentTenantId")
    String getCurrentTenantId(@RequestBody List<TenantUserDTO> tenants,
                              @RequestParam(value = "tenantCode")String tenantCode);


    @PostMapping("/v1/rest/auth/allow")
    boolean allow(@RequestParam("uri") String uri, @RequestParam("method") String method,
                  @RequestBody Set<String> authoritys);

}
